package ControlLayer;

import java.util.ArrayList;
import java.util.Date;

import ModelLayer.*;
import DBLayer.*;

public class FacilityCtr {
	private IFDBFacility db;

	public FacilityCtr() {
		db = new DBFacility();
	}

	public int insertFacility(Facility facility) {
		return db.insertFacility(facility);
	}

	public int updateFacility(long ID, Facility facility) {
		return db.updateFacility(ID, facility);
	}

	public Facility getFacility(long ID) {
		return db.getFacility(ID);
	}

	public ArrayList<Facility> getFacilities() {
		return db.getFacilities();
	}

	public ArrayList<Facility> getFacilities(ActivityType at) {
		return db.getFacilities(at);
	}

	public int removeFacility(long ID) {
		return db.removeFacility(ID);
	}

	public boolean isFacilityAvailable(Date startDate, Facility facility) {
		ActivityBookingCtr ctr = new ActivityBookingCtr();
		ArrayList<ActivityBooking> bookings = ctr.getAllActivityBookings();
		for (ActivityBooking b : bookings) {
			if (b.getFacility().getID() == facility.getID()) {
				if (b.getStartHour().compareTo(startDate) == 0)
					return false;
			}
		}
		return true;
	}
}
